package com.systop.dxjj.modules.teacher.controller;

import com.alibaba.fastjson.JSON;
import com.systop.dxjj.common.pojo.ResponseResult;
import com.systop.dxjj.common.pojo.Teacher;
import com.systop.dxjj.common.pojo.TeacherUser;
import com.systop.dxjj.common.utils.R;
import com.systop.dxjj.common.utils.RedisCache;
import com.systop.dxjj.modules.teacher.service.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@RestController
@Api("教员管理模块")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;

    @Autowired
    private RedisCache redisCache;

    TeacherUser teacherUser;
    /**
     * 查询所有教员信息
     */
    @GetMapping("/selectAllTeachs")
    @ApiOperation(value = "查询所有教员信息",notes = "教员信息")
    public R selectAllTeachs(){

        return teacherService.selectAllTeachs();
    }

    /**
     * 教员登录
     */
    @PostMapping("/loginTeach")
    @ApiOperation(value = "教员登录",notes = "教员信息")
    public R loginTeachs(@RequestBody Teacher teacher){
        return teacherService.loginTeachs(teacher);
    }

    /**
     *根据id查询教员信息
     */
    @GetMapping("/selectTeachById/{id}")
    @ApiOperation(value = "根据id查询教员信息",notes = "教员信息")
    public R  selectTeachById(@PathVariable Integer id){

        return teacherService.selectTeachById(id);
    }


    /**
     *根据姓名查询教员信息
     */
    @GetMapping("/selectTeachByName/{name}")
    @ApiOperation(value = "根据教员姓名查询学员信息",notes = "教员信息")
    public R  selectTeachByName(@PathVariable String name){
        return teacherService.selectTeachByName(name);
    }
    /**
     *根据姓名模糊查询教员信息
     */
    @GetMapping("/selectTeachByVagueName/{name}")
    @ApiOperation(value = "根据教员姓名模糊查询学员信息",notes = "教员信息")
    public R selectTeachByVagueName (@PathVariable String name){
        return teacherService.selectTeachByVagueName(name);
    }

    /**
     *插入教员信息
     */
    @PostMapping("/insertTeach")
    @ApiOperation(value = "插入教员信息",notes = "教员信息")
    public R  insertTeach(@RequestBody Teacher teacher){
        return teacherService.insertTeach(teacher);
    }

    @PostMapping("/insertTeach2")
    public R  insertTeach2(@RequestBody Teacher teacher){
        return teacherService.insertTeach2(teacher);
    }

    /**
     *更新教员信息
     */
    @GetMapping("/updateTeach")
    @ApiOperation(value = "更新教员信息",notes = "教员信息")
    public R updateTeach(@RequestBody Teacher teacher){
        return teacherService.updateTeach(teacher);
    }

    /**
     *删除教员信息
     */
    @GetMapping("/deleteTeach/{id}")
    @ApiOperation(value = "删除教员信息",notes = "教员信息")
    public R  deleteTeach(@PathVariable Integer id){
        return teacherService.deleteTeach(id);
    }

    @PostMapping("/teacher/login")
    public ResponseResult login(@RequestBody Teacher teacher){
        //登录
        return teacherService.teachLogin(teacher);
    }

    @RequestMapping("/teacher/logout")
    public ResponseResult logout(){
        return teacherService.teachlogout();
    }


}
